// CustomPalette.js
export default class CustomPalette {
  constructor(bpmnFactory, create, elementFactory, palette, translate) {
    this.bpmnFactory = bpmnFactory;
    this.create = create;
    this.elementFactory = elementFactory;
    this.translate = translate;

    palette.registerProvider(this);
  }
  // 这个函数就是绘制palette的核心
  getPaletteEntries(element) {
    const { bpmnFactory, create, elementFactory, translate } = this;
    /**
     * 创建一个类型为`bpmn:Task`的元素, 你还可以用来创建`bpmn:StartEvent、bpmn:ServiceTask、bpmn:ExclusiveGateway`等等
     * @returns
     */
    function createTask() {
      return function (event) {
        const businessObject = bpmnFactory.create("bpmn:Task");
        businessObject["custom"] = 1;
        const shape = elementFactory.createShape({
          type: "bpmn:Task",
          businessObject,
        });
        create.start(event, shape);
      };
    }

    return {
      "create.lindaidai-task": {
        group: "model", // group: 属于哪个分组, 比如tools、event、gateway、activity等等,用于分类
        className: "icon-custom lindaidai-task",
        title: translate("创建一个类型为lindaidai-task的任务节点"),
        action: {
          // 操作
          dragstart: createTask(), // 开始拖拽时调用的事件
          click: createTask(), // 点击时调用的事件
        },
      },
    };
  }
}

CustomPalette.$inject = [
  "bpmnFactory",
  "create",
  "elementFactory",
  "palette",
  "translate",
];
